package cc.dd.marketing.core;


import cc.dd.marketing.api.request.base.AbstractBaseRequest;
import cc.dd.marketing.core.base.RequestParser;
import cc.dd.marketing.core.domain.RuleInnerDTO;
import cc.dd.marketing.rule.base.Rule;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 活动实体组装
 *
 * @author dongsufeng
 * @date 2022/9/9 2:28 PM
 */
@Slf4j
public abstract class AbstractRequestDTOParser<REQ extends AbstractBaseRequest, DTO extends RuleInnerDTO> implements RequestParser<REQ,DTO> {


    /**
     * 构造活动规则集合
     */
    protected abstract List<Rule> buildRules(DTO innerDTO);

    /**
     * 组装DTO
     *
     * @param request
     * @return
     */
    protected DTO assembleDTO(REQ request,DTO innerDTO) {
        return innerDTO;
    }


    public RuleInnerDTO buildDTO(REQ request, DTO baseRequestDTO) {
        baseRequestDTO= assembleDTO(request, baseRequestDTO);
        baseRequestDTO.setRules(buildRules(baseRequestDTO));
        return baseRequestDTO;
    }
}
